package com.example.lenjor.sprite.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.lenjor.sprite.R;
import com.example.lenjor.sprite.adapter.ChongZhiAdapter;
import com.example.lenjor.sprite.bean.ChongZhiInfo;
import com.example.lenjor.sprite.util.AnimUtil;

import java.util.ArrayList;

/**
 * Created by lenjor on 2017/7/2 0002.
 */
public class ChongZhiView extends BaseView {
    private ImageView iv_close;
    private Dialog dialog;
    private ListView lv_cz;


    //先弄着静态的一个集合（假数据）
    private ArrayList<ChongZhiInfo> data;
    public ChongZhiView(Context context) {
        super(context);
        setContextView(R.layout.view_chongzhi);
        initUI();
        initLvCSAdapter();
    }
    private void initLvCSAdapter() {
        data = new ArrayList<ChongZhiInfo>();
        data.add(0, new ChongZhiInfo("优惠90%", 8.5, "月卡", R.mipmap.item1, "含月卡，10颗钻石", 58, "58元"));
        data.add(1, new ChongZhiInfo("优惠60%", 9.3, "月卡", R.mipmap.item2, "多送10颗钻石", 58, "69元"));
        data.add(2, new ChongZhiInfo("优惠70%", 9.8, "月卡", R.mipmap.item3, "送1000骨币，5颗钻石", 58, "36元"));
        data.add(2, new ChongZhiInfo("优惠95%", 9.5, "月卡", R.mipmap.item1, "送召唤师神秘礼包一份", 58, "45元"));
        ChongZhiAdapter adapter = new ChongZhiAdapter(context, data);
        lv_cz.setAdapter(adapter);
    }

    public void show(){
        if (dialog == null){
            dialog = new Dialog(context,R.style.MyDialog);
            //-2:自适应   -1：占满
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(-2,-2);
            dialog.setContentView(view,params);
        }
        dialog.show();
    }


    @Override
    protected void initUI() {
        iv_close = (ImageView) findViewById(R.id.iv_close);
        AnimUtil.addOnTouchListener(iv_close, 0.5f, 0.5f, new AnimUtil.AnimListener() {
            @Override
            public void down(View v) {

            }

            @Override
            public void move(View v) {

            }

            @Override
            public void up(View v) {
                dialog.dismiss();
            }
        });

        lv_cz = (ListView) findViewById(R.id.lv_cz);

    }


}
